package leetcode;

import java.util.Scanner;

public class PatternS {
    public static boolean wordPattern(String pattern, String s){
        String[] s1 = s.split(" ");
        boolean flag = true;
        if(pattern.length() != s1.length){
            return false;
        }
        for (int i = 0; i < pattern.length()/2; i++) {
            for (int j = i+1; j < pattern.length(); j++) {
                char a = pattern.charAt(i);
                char b = pattern.charAt(j);
                if(a == b){
                    flag = (s1[i].equals(s1[j])?true:false);
                }else{
                    flag =(s1[i].equals(s1[j])?false:true);
                }
                if(flag == false){
                    break;
                }
            }
            if(flag == false){
                break;
            }
        }
        return flag;
    }


    public static void main(String[] args) {
        String pattern,s;
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入单词规律：");
        pattern = scanner.nextLine();
        System.out.println("请输入单词string（单个空格分隔 前后无空格）：");
        s = scanner.nextLine();
        System.out.println(wordPattern(pattern, s));
    }
}
